package org.groupg.project.dagdemo;

import com.lmax.disruptor.EventHandler;
import com.lmax.disruptor.RingBuffer;

public class Stage1EventHandler implements EventHandler<Stage1Event> {
    private final RingBuffer<Stage2Event> stage2RingBuffer;

    public Stage1EventHandler(RingBuffer<Stage2Event> stage2RingBuffer) {
        this.stage2RingBuffer = stage2RingBuffer;
    }

    @Override
    public void onEvent(Stage1Event event, long sequence, boolean endOfBatch) {
        System.out.println("Stage 1 processing: " + event.getValue());

        // Create a new event for stage 2
        long nextSequence = stage2RingBuffer.next();
        try {
            Stage2Event stage2Event = stage2RingBuffer.get(nextSequence);
            stage2Event.setProcessedValue(event.getValue() * 2); // Example processing
        } finally {
            stage2RingBuffer.publish(nextSequence);
        }
    }
}